package com.seewell.algo;

import org.omg.CORBA.SystemException;

import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * fib 动态规划发实现的
 *
 * @author ZHB
 * @Date 2021/3/25
 */
public class Fib_dynamic {

    public static String[] output = new String[100];

    public static String fib(int n){
        System.out.print("当前参数："+n);
        if(output[n] == null)
        {
            switch(n){
                case 0:
                    System.out.println("执行了n=0");
                    output[n] = "0";
                    break;
                case 1:
                    System.out.println("执行了n=1");
                    output[n] = "1";
                    break;
                default:
                    System.out.println("执行了n="+n);
                    return output[n] = String.valueOf(Integer.valueOf(fib(n-1)) + Integer.valueOf(fib(n-2)));
            }

        }
        return output[n];
    }

    public static void main(String[] args) {
        System.out.println(fib(6));
        Stream.of(output).collect(Collectors.toList()).forEach(System.out::println);

    }
}
